<template>
	<view class="u-wrap">
		<view class="u-search-box">
			<u-search shape="square" :show-action="false" :clearabled="true" :animation="false" v-model="keywords"
				@search="toList"></u-search>
		</view>
		<view class="container" :style="{'height':cateHeight+'px'}">
			<!-- left左侧一级分类列表 -->
			<scroll-view scroll-y class="left">
				<!-- 循环遍历的 -->
				<view class="left_list" v-for="(item,index) in leftCateList" :key="index">
					<text :class="currentIndex==index?'activeIndex':''"
						@click="changeList(index,item.id)">{{item.catename}}</text>
				</view>
			</scroll-view>
			<!-- right右侧二级分类详情 -->
			<scroll-view scroll-y class="right" :scroll-into-view="id">
				<view class="right_box" :id="'id'+index" v-for="(item,index) in catelist" :key="index">
					<!-- {{catelist}} -->
					<view class="row_title">{{item.catename}}</view>
					<view class="row">
						<view class="row_list" v-for="(m,i) in item.children" :key="i" @click="goList(m.id)">
							<image :src="m.img" mode="widthFix"></image>
							<text>{{m.catename}}</text>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
	</view>
</template>
<script>
	// 引入分类测试数据
	// import cateData from '@/utils/classify.data.js'

	export default {
		data() {
			return {
				id: 'id0', //设置右侧默认置顶分类id
				currentIndex: 0, //默认左侧分类选中下标
				cateHeight: '', //初始化分类容器高度
				catelist: '', //右侧初始化分类数据
				leftCateList: '', //左侧初始化分类数据
				keywords: '',
				// cateId: 1, //分类id
			}
		},
		onLoad() {
			// 动态获取当前设备的高度
			this.cateHeight = uni.getSystemInfoSync().windowHeight;
			this.classify();
			// this.leftList();

			// this.rightList()
		},
		onShow() {},

		methods: {
			// 搜索
			toList() {

				uni.navigateTo({
					url: '/pages/list/list?keyword=' + this.keywords
				})
			},

			// 请求分类列表
			classify() {
				this.$http({
					url: '/getcates'
				}).then(res => {
					console.log(res);
					this.leftCateList = res.data.list
					this.catelist = res.data.list;
					this.catelist.forEach((item, index) => {
						item.children.forEach((item1, index1) => {
							item1.img = this.$baseUrl + item1.img;
						})
					})
					console.log(this.catelist, 12313);
				})
			},
			// 切换左侧列表
			changeList(index) {
				this.currentIndex = index;
				this.id = 'id' + index;
			},
			// 跳转列表页面
			goList(cateid) {
				uni.navigateTo({
					url: '/pages/list/list?type=2&cateid=' + cateid,

				})
			}
		}

	}
</script>

<style lang="scss" scoped>
	/* 引入样式 */
	// @import url("@/static/css/cate.css");
	.u-wrap {
		height: calc(100vh);
		/* #ifdef H5 */
		height: calc(100vh - var(--window-top));
		/* #endif */
		display: flex;
		flex-direction: column;
	}

	.u-search-box {
		// padding: 18rpx 0rpx;
		padding: 20rpx 5%;
		background-color: #FF6040;
		box-sizing: border-box;
		position: fixed;
		top: var(--window-top);
		left: 0;
		z-index: 2;
		width: 100%;
		line-height: 140rpx;
	}

	.container {
		display: flex;
		margin-top: 140rpx;
		// height: 90vh;
		overflow: hiddren;
	}

	.left {
		flex: 1;
		border-right: 2rpx solid #F0F0F0;
		overflow: auto;
	}

	.left .left_list {
		width: 100%;
		// height: 100%;
		text-align: center;
		line-height: 150rpx;
		color: #999999;
		font-size: 28rpx;
	}

	.left .activeIndex {
		// background-color: red;
		color: red;
	}

	.right {
		flex: 2;
		background-color: #f2f2f2;
		padding-bottom: 50rpx;
		overflow: auto;
	}

	.right .right_box {
		margin: 25rpx 25rpx;
		background-color: white;
		overflow: hidden;
	}

	.right .right_box .row_title {
		font-size: 32rpx;
		font-weight: bold;
		margin: 20rpx 0 10rpx 20rpx;
	}

	.right .right_box .row {
		display: flex;
		flex-wrap: wrap;
	}

	.right .right_box .row .row_list {
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		align-items: center;
		height: 150rpx;
		width: 33%;
		align-items: center;
		font-size: 24rpx;
		color: #999999;
		margin-bottom: 20rpx;
	}

	.right .right_box .row .row_list image {
		width: 120rpx;
	}

	/* 点击左侧导航，显示动态样式 */
	.activeList {
		/* border-left: 6rpx solid #f26b11; */
		color: #FF6040;
		font-size: 32rpx;
		font-weight: bold;
	}
</style>